﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.SessionState;

namespace WebSite
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class UpLoadFiles : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            string outMessage = string.Empty;
            context.Response.ContentType = "text/plain";
            //Int64 FileP = Int64.Parse(context.Request["FilePositon"].ToString());
            Int64 FileP = 2971;
            System.Web.HttpFileCollection FileLists = System.Web.HttpContext.Current.Request.Files;
            //System.Web.HttpPostedFile hfc = Request.Files[0];
            for (int i = 0; i < FileLists.Count; i++)
            {
                HttpPostedFile postfile = FileLists[i];
                byte[] buffer = new byte[postfile.InputStream.Length];
                postfile.InputStream.Read(buffer, 0, buffer.Length);
                System.IO.FileStream fs = new System.IO.FileStream(@"c:\test.doc", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
                fs.Position = FileP;
                fs.Write(buffer, 0, buffer.Length);
                fs.Flush();
                fs.Close();
                outMessage += "UpLoadFileSize=" + (FileP + postfile.InputStream.Length).ToString();
            }
            outMessage += "querystring:" + System.Web.HttpContext.Current.Request.QueryString.Keys.Count.ToString();
            outMessage += "form:" + System.Web.HttpContext.Current.Request.Form.Keys.Count.ToString();
            for (int i = 0; i < HttpContext.Current.Request.Form.Keys.Count; i++)
            {

                outMessage += System.Web.HttpContext.Current.Request.Form.Keys[i].ToString() + ":" + System.Web.HttpContext.Current.Request.Form[i];
                outMessage += "AllKeys" + System.Web.HttpContext.Current.Request.Form.AllKeys.ToString();
            }
            System.Web.HttpContext.Current.Response.Write(outMessage);
            System.Web.HttpContext.Current.Response.End();
            //context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
